package com.yorge.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.yorge.client.PaymentClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/order")
@DefaultProperties(defaultFallback = "default_fallback")
public class OrderController {
    @Resource
    PaymentClient paymentClient;

    @GetMapping("/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        return paymentClient.paymentInfo_OK(id);
    }
/* @HystrixCommand(fallbackMethod = "paymentInfo_TimeOut_fallback", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")
    })*/
    @HystrixCommand
    @GetMapping("/timeout/{id}")
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
        return paymentClient.paymentInfo_TimeOut(id);
    }

    public String default_fallback(){
        return "controller全局默认，线程池："+Thread.currentThread().getName()+"   系统繁忙, 请稍候再试  ,id：哭了哇呜";
    }

    public String paymentInfo_TimeOut_fallback(Integer id){
        return "线程池："+Thread.currentThread().getName()+"   系统繁忙, 请稍候再试  ,id：  "+id+"\t"+"哭了哇呜";
    }
}
